import pytest

from page.page_in import PageIn
from tools.get_driver import GetDriver
from tools.get_log import GetLog
from tools.read_yaml import read_yaml

logger = GetLog.get_logger()


class TestZoSearchHistory:
    # 1.初始化
    def setup_class(self):
        driver = GetDriver.get_app_driver()
        self.zoPageSearchHistory = PageIn(driver).page_get_ZoPageSearchHistory()

    # 2.结束
    def teardown_class(self):
        GetDriver.quit_app_driver()

    # 3.转业务方法
    @pytest.mark.run(order=1)
    @pytest.mark.parametrize('search_text', read_yaml('app_zo_search_history.yaml'))
    def test_zo_search_history(self, search_text):
        self.zoPageSearchHistory.zo_page_search_history(search_text)
        try:
            # 调用全局搜索业务方法
            print(search_text)
            assert self.zoPageSearchHistory.page_find_search_history() != search_text[0]
        except Exception as e:
            # 日志
            logger.error(e)
            # 截图
            self.zoPageSearchHistory.base_get_image()
            # 抛异常
            raise

    # 4.检查历史搜索记录方法
    @pytest.mark.run(order=2)
    def test_zo_check_history_search_recoder(self):
        try:
            assert self.zoPageSearchHistory.page_check_history_search_recorder()
        except Exception as e:
            # 日志
            logger.error(e)
            # 截图
            self.zoPageSearchHistory.base_get_image()
            # 抛异常
            raise


